package com.example.demo.commons.core.robot.message;

import cn.hutool.core.util.ArrayUtil;
import com.example.demo.commons.core.robot.message.base.BaseMessage;
import com.example.demo.commons.core.robot.message.base.Constants;
import lombok.Getter;

@Getter
public class MarkdownMessage extends BaseMessage<MarkdownMessage> {
    private String content;
    private String[] mentioned_mobile_list;

    private MarkdownMessage(String content, String... mobiles) {
        super(Constants.MARKDOWN);
        this.content = content;
        this.mentioned_mobile_list = mobiles;
    }

    public static MarkdownMessageBuilder builder() {
        return new MarkdownMessageBuilder();
    }

    public static class MarkdownMessageBuilder {
        private String content;
        private String[] mobiles;

        MarkdownMessageBuilder() {
        }

        public MarkdownMessageBuilder content(String content) {
            this.content = content;
            return this;
        }

        public MarkdownMessageBuilder atAll() {
            if (this.mobiles != null && this.mobiles.length > 0) {
                ArrayUtil.append(this.mobiles, Constants.ALL);
            } else {
                this.mobiles = new String[]{Constants.ALL};
            }
            return this;
        }

        public MarkdownMessageBuilder at(String... mobiles) {
            this.mobiles = mobiles;
            return this;
        }

        public MarkdownMessage build() {
            return new MarkdownMessage(this.content, this.mobiles);
        }
    }
}
